using System.Collections.Generic;
using System.Web.Security;

namespace ExampleMvcApplication.Services
{
    public class VerySimpleMembershipService : IMembershipService
    {
        private static readonly IDictionary<string, string> _store = new Dictionary<string, string>();

        static VerySimpleMembershipService()
        {
            _store["jmcd"] = "secret";
        }

        public int MinPasswordLength
        {
            get { return 2; }
        }

        public bool ValidateUser(string userName, string password)
        {
            return _store.ContainsKey(userName) && _store[userName] == password;
        }

        public MembershipCreateStatus CreateUser(string userName, string password, string email)
        {
            if (_store.ContainsKey(userName)) return MembershipCreateStatus.DuplicateUserName;
            _store[userName] = password;
            return MembershipCreateStatus.Success;
        }

        public bool ChangePassword(string userName, string oldPassword, string newPassword)
        {
            if (ValidateUser(userName, oldPassword))
            {
                _store[userName] = newPassword;
                return true;
            }
            return false;
        }
    }
}